package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.ShopCart;
import cn.wolfcode.trip.base.mapper.ShopCartMapper;
import cn.wolfcode.trip.base.service.IShopCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Copyright: Copyright (c) 2019 Super520
 * 描述：购物车实现类
 *
 * @package: cn.wolfcode.trip.base.service.impl
 * @author: Patch
 * @date: 2019/6/2 15:37
 * 总结:
 */
@Service
public class ShopCartServiceImpl implements IShopCartService {
    @Autowired
    private ShopCartMapper shopCartMapper;

    @Override
    public void saveOrUpdate(ShopCart shopCart) {
        if (shopCart.getId() != null) {
            shopCart.setUpdateTime(new Date());
            shopCartMapper.updateByPrimaryKey(shopCart);
        } else {
            shopCart.setCreateTime(new Date());
            shopCartMapper.insert(shopCart);
        }
    }

    @Override
    public List<ShopCart> listAll() {
        return shopCartMapper.selectAll();
    }

    @Override
    public ShopCart get(Long id) {
        return shopCartMapper.selectByPrimaryKey(id);
    }

    @Override
    public void delete(Long id) {
        shopCartMapper.deleteByPrimaryKey(id);
    }

    @Override
    public   List<Map<String, Object>> listAllByUserId(Long uId) {
        return shopCartMapper.selectAllByUserId(uId);
    }

    @Override
    public void deleteAll(Long uId) {
        shopCartMapper.deleteAll(uId);
    }
}
